package com.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mapper.auto.StuSubjectRelMapper;
import com.model.auto.StuSubjectRel;
import com.service.IStuSubjectRelService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 学生擅长门类关系表 服务实现类
 * </p>
 *
 * @author astupidcoder
 * @since 2022-09-14
 */
@Service
public class StuSubjectRelServiceImpl extends ServiceImpl<StuSubjectRelMapper, StuSubjectRel> implements IStuSubjectRelService {

    @Override
    public Float getProficiency(Integer stuId, String majorCode) {
        List<Float> proficiencyList = baseMapper.getProficiencyList(stuId, majorCode);
        if(Objects.isNull(proficiencyList) || proficiencyList.size()==0){
            return 0f;
        }
        Float proficiency = 0f;
        for(Float p:proficiencyList){
            proficiency= proficiency+p;
        }
        return Float.parseFloat(String.format("%.2f", proficiency/3));
    }
}
